package com.edu.framework.websocket.message.base;


import com.edu.common.utils.StringUtils;
import lombok.Data;

@Data
public class Response<T> extends Message<T>{

    public static final int ERRNO_OK=0;
    public static final int ERRNO_FAIL=1;
    public static final String ERRMSG_OK="success";


    private int errno=ERRNO_OK;
    private String errmsg="ERRMSG_OK";


    private Response(String type,int errno,String errmsg,String key,T data){
        super.setType(type);
        this.errno=errno;
        this.errmsg = errmsg;
        if(StringUtils.isNotEmpty(key)){
            addData(key,data);
        }
    }

    public static <T> Response<T> ok(String type,String key,T data){
        return new Response<>(type,ERRNO_OK,ERRMSG_OK,key,data);
    }

    public static <T> Response<T> fail(String type, String errmsg){
        return new Response<>(type,ERRNO_FAIL,errmsg,null,null);
    }


}
